package com.beiding.pojo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.util.Assert;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
import java.util.Set;

@Getter
@Setter
public class Room implements Resource{

    //房源名称(需要)
    @NotNull
    @Size(min = 2,max = 10,message = "大于2小于10个字")
    private String name;

    //房源描述(需要)
    @NotNull
    @Size(min = 5,max = 200,message = "大于5小于200个字")
    private String description;

    //房源的地理位置(需要)
    @NotNull
    private Location location ;

    //房间定价(需要)
    @NotNull
    private List<Price> prices;

    //房间图片的静态资源ID(可选)
    private Set<String> images;


    /*********** 自动管理 ***********/

    @Id
    private String id;

    private String holderId;

    //房间的使用者
    private String theUser;

    //房源是否已经发布
    private boolean published;

    //房源是否被冻结
    private boolean freeze;

    //初始化房源
    public void init() {

        //校验房间信息
        Assert.isTrue(-180<=location.getLongitude()&&location.getLongitude()<180&&-80<=location.getLatitude()&&location.getLatitude()<=80,"无效的坐标");

        id = holderId = theUser = null;
        published = freeze = false;
    }


    //合并信息
    public void merge(Room room) {

        //房间名称
        this.name = room.name;

        //房间的图片资源
        this.images = room.images;

        //房间位置
        this.location = room.location;

        //房间定价
        this.description = room.description;

        //房源持有者
        this.holderId = room.holderId;

    }


    @Override
    public String toString() {
        return id;
    }



}
